package net.crazyblock.mobilesafe.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Utils {
	/**
	 * MD5加密算法
	 * @param password
	 * @return
	 */
	public static String md5Password(String password) {
		try {
			MessageDigest digest = MessageDigest.getInstance("md5");
			byte[] bytes = digest.digest(password.getBytes());
			StringBuffer buffer = new StringBuffer();
			for (byte b : bytes) {
				int number = b & 0xff;// 加盐
				String hex = Integer.toHexString(number);
				if (hex.length() == 1) {
					buffer.append("0");
				}
				buffer.append(hex);
			}

			return buffer.toString();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}

	}
}
